package com.bobbygu.googlearchitecture.viewmodel

import android.arch.lifecycle.MutableLiveData
import android.arch.lifecycle.ViewModel
import android.os.Handler
import com.bobbygu.googlearchitecture.bean.Story
import com.bobbygu.googlearchitecture.bean.User
import java.util.ArrayList

/**
 *
 * # time: 2017/12/20 13:06
 * # e-mail: gubojun@csii.com.cn
 * @author 顾博君
 * @since 1.0
 */
class MyViewModel : ViewModel() {
    var users: MutableLiveData<List<User>> = MutableLiveData()
        get() {
            if (field.value == null) {
                Handler().postDelayed({ loadUsers() }, 3000)
            }
            return field
        }
    var stories: MutableLiveData<List<Story>> = MutableLiveData()

    private fun loadUsers() {
        val list = ArrayList<User>()
        val user = User()
        user.age = "25"
        user.name = "Bobby"
        list.add(user)
        users.value = list
    }
}